home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / math / gle-3.000 / gle-3 / gle / d_curses.c < prev    next >
C/C++ Source or Header  |  1995-02-07  |  10KB  |  448 lines

  1. /*--------------------------------------------------------------*/
  2. /*      VT100 Driver 1.0 , for GLE V3.0         */
  3. /*---------------------------------------------------------------------------*/
  4. #include "all.h"
  5. #include <math.h>
  6. #include "core.h"
  7. #include "mygraph.h"
  8. #include "mydev.h"
  9. #define GS 29
  10. #define FF 12
  11. #define MAXX (79)
  12. #define MAXY (23)
  13. int screenbit[MAXX+4][MAXY+4];
  14. int ingraphmode;
  15. extern struct gmodel g;
  16. /*---------------------------------------------------------------------------*/
  17. #define pi 3.141592653
  18. #define true (!false)
  19. #define BLACKANDWHITE 1
  20. #define ESC 27
  21. #define false 0
  22. #define dbg if ((gle_debug & 64)>0)
  23. #define stop if ((gle_debug & 128)>0) return
  24. extern int gle_debug;
  25. int incap=true;
  26. int getch(void);
  27. /*---------------------------------------------------------------------------*/
  28. /* The global variables for the PC screen driver */
  29. /*-----------------------------------------------*/
  30.  
  31. int i,l,j,ix,iy;
  32. double f;
  33. double devxcm=23,devycm=15.5;
  34. FILE *hpfile;
  35.  
  36. #define gerr() i = graphresult(); if (i!=0) printf("Graph error: %s \n",grapherrormsg(i));
  37. #define sx(v) ( ((v) * d_xscale))
  38. #define sy(v) ( (((v) * d_yscale)))
  39. #define rx(v) ( ((v) * d_xscale))
  40. #define ry(v) ( (((v) * d_yscale)))
  41.  
  42. double d_scale, d_xscale, d_yscale;
  43. int d_graphmode;
  44. int d_fillstyle=1,d_fillcolor;
  45. int d_lstyle,d_lwidth;
  46. char outstr[400];
  47.  
  48. d_devcmd(char *s)
  49. {}
  50. /*---------------------------------------------------------------------------*/
  51. d_dfont(char *c)
  52. {
  53.     /* only used for the DFONT driver which builds fonts */
  54. }
  55. /*---------------------------------------------------------------------------*/
  56. static char lastline[80];
  57. d_message(char *s)
  58. {
  59.     static int single_step;
  60.     int oldcolor,oldx,oldy;
  61.     w_message(s);
  62. }
  63. /*---------------------------------------------------------------------------*/
  64. d_source(char *s)
  65. {
  66.     s=s;
  67. }
  68. /*---------------------------------------------------------------------------*/
  69. d_get_type(char *t)
  70. {
  71.     strcpy(t,"INTERACTIVE, VT100, VAX");
  72. }
  73. /*---------------------------------------------------------------------------*/
  74. d_set_path(int onoff)
  75. {}
  76. /*---------------------------------------------------------------------------*/
  77. d_newpath()
  78. {
  79. }
  80. /*---------------------------------------------------------------------------*/
  81. extern char output_file[];
  82. d_open(double width, double height)
  83. {
  84.     /* Get largest rectangle we can fit on the screen */
  85.     d_scale = devxcm / width;
  86.     f = devycm / height;
  87.     if (f<d_scale) d_scale = f;
  88.     d_xscale = d_scale * MAXX / devxcm; /* Device Scale X, Device Scale y */
  89.     d_yscale = d_scale * MAXY / devycm;
  90. }
  91. /*---------------------------------------------------------------------------*/
  92. d_tidyup()
  93. {
  94. }
  95. d_close()
  96. {
  97.     int x,y;
  98.     char oneline[200];
  99.     int lastinv=false;
  100.     g_flush();
  101.  
  102.     clrscr();
  103.     for (y = MAXY-1;y>= 0;y--) {
  104.       oneline[0] = 0;
  105.       for (x=0;x<=MAXX;x++) {
  106.         if (screenbit[x][y]==0) strcat(oneline," ");
  107.         else strcat(oneline,"#");
  108.       }
  109.       gotoxy(1,MAXY-y);
  110.       wprintf("%s",oneline);
  111.     }
  112.     scr_refresh();
  113.     text_inkey();
  114. }
  115. /*---------------------------------------------------------------------------*/
  116. d_set_line_cap(int i)
  117. {
  118.     i++;
  119. }
  120. /*---------------------------------------------------------------------------*/
  121. d_set_line_join(int i)
  122. {
  123.     i++;
  124. }
  125. /*---------------------------------------------------------------------------*/
  126. d_set_line_miterlimit(double d)
  127. {
  128.     i++;
  129. }
  130. /*---------------------------------------------------------------------------*/
  131. d_set_line_width(double w)
  132. {
  133. }
  134. /*---------------------------------------------------------------------------*/
  135. d_set_line_styled(double dd)
  136. {}
  137. d_set_line_style(char *s)
  138. {
  139.     d_lstyle = 2;
  140.     if (strcmp(s,"")==0) d_lstyle = 1;
  141.     if (strcmp(s,"1")==0) d_lstyle = 1;
  142. }
  143. /*---------------------------------------------------------------------------*/
  144. d_fill()
  145. {
  146. }
  147. /*---------------------------------------------------------------------------*/
  148. d_fill_ary(int nwk,double (*wkx)[],double (*wky)[])
  149. {
  150.     int i;
  151. /*      fprintf(psfile,"%g %g moveto \n",(*wkx)[0],(*wky)[0]);
  152.     for (i=1;i<nwk;i++)
  153.         fprintf(psfile,"%g %g l \n",(*wkx)[i],(*wky)[i]);
  154. */
  155. }
  156. d_line_ary(int nwk,double (*wkx)[],double (*wky)[])
  157. {
  158.     int i;
  159. /*
  160.     g_dev( (*wkx)[0], (*wky)[0], &ix, &iy);
  161.     moveto(ix,iy);
  162.     for (i=1;i<nwk;i++) {
  163.         g_dev( (*wkx)[i], (*wky)[i], &ix, &iy);
  164.         lineto(ix,iy);
  165.     }
  166. */
  167. }
  168. /*---------------------------------------------------------------------------*/
  169. d_stroke()
  170. {
  171. }
  172. /*---------------------------------------------------------------------------*/
  173. d_clip()
  174. {
  175. }
  176. /*---------------------------------------------------------------------------*/
  177. d_set_matrix(double newmat[3][3])
  178. {
  179. }
  180. /*---------------------------------------------------------------------------*/
  181. d_move(double zx,double zy)
  182. {
  183. }
  184. /*---------------------------------------------------------------------------*/
  185. d_reverse()     /* reverse the order of stuff in the current path */
  186. {
  187. }
  188. /*---------------------------------------------------------------------------*/
  189. d_closepath()
  190. {
  191.     g_line(g.closex,g.closey);
  192. }
  193. /*---------------------------------------------------------------------------*/
  194. int vt100line(int  x1, int  y1, int  x2, int  y2);
  195. int hpglxy(double xx, double yy);
  196. d_line(double zx,double zy)
  197. {
  198.     static double ix,iy,ux,uy;
  199.     g_dev(g.curx,g.cury,&ux,&uy);
  200.     g_dev(zx,zy,&ix,&iy);
  201.     vt100line(sx(ux),sy(uy),sx(ix),sy(iy));
  202. }
  203. /*---------------------------------------------------------------------------*/
  204. /* int screenbit[MAXX+1][MAXY+1]; */
  205. xxvt100line(int  x1, int  y1, int  x2, int  y2)
  206. {
  207. #define sign(x) ((x) > 0 ? 1: ((x) == 0 ? 0: (-1)))
  208.     int dx,dy,dxabs,dyabs,i,px,py,sdx,sdy,x,y;
  209.     if (x1<0) x1 = 0;
  210.     if (x1>MAXX) x1 = MAXX;
  211.     if (y1<0) y1 = 0;
  212.     if (y1>MAXY) y1 = MAXY;
  213.     if (x2<0) x2 = 0;
  214.     if (x2>MAXX) x2 = MAXX;
  215.     if (y2<0) y2 = 0;
  216.     if (y2>MAXY) y2 = MAXY;
  217.  
  218.     /* line algorithym begins */
  219.  
  220.     dx = x2 - x1;
  221.     dy = y2 - y1;
  222.     sdx = sign(dx);
  223.     sdy = sign(dy);
  224.     dxabs = abs(dx);
  225.     dyabs = abs(dy);
  226.     x = 0;
  227.     y = 0;
  228.     px = x1;
  229.     py = y1;
  230.     if (dxabs >= dyabs) {
  231.         for (i=0; i<=dxabs; i++) {
  232.             y += dyabs;
  233.             if (y>=dxabs) {
  234.                 y -= dxabs;
  235.                 py += sdy;
  236.             }
  237.             screenbit[px][py] = '#';
  238.             px += sdx;
  239.         }
  240.     } else {
  241.         for (i=0; i<=dyabs; i++) {
  242.             x += dxabs;
  243.             if (x>=dyabs) {
  244.                 x -= dyabs;
  245.                 px += sdx;
  246.             }
  247.             screenbit[px][py] = '#';
  248.             py += sdy;
  249.         }
  250.     }
  251. }
  252.  
  253. uint32 PATTERN = 0xFFFFFFFF;
  254. int LINEWIDTH=1;
  255.  
  256. vt100line(int  x1, int  y1, int  x2, int  y2)
  257. {
  258. #define sign(x) ((x) > 0 ? 1:  ((x) == 0 ? 0:  (-1)))
  259.     int dx, dy, dxabs, dyabs, i, j, px, py, sdx, sdy, x, y;
  260.     uint32 mask=0x80000000;
  261.  
  262.     if (x1<0) x1 = 0;
  263.     if (x1>MAXX) x1 = MAXX;
  264.     if (y1<0) y1 = 0;
  265.     if (y1>MAXY) y1 = MAXY;
  266.     if (x2<0) x2 = 0;
  267.     if (x2>MAXX) x2 = MAXX;
  268.     if (y2<0) y2 = 0;
  269.     if (y2>MAXY) y2 = MAXY;
  270.  
  271.     dx = x2 - x1;
  272.     dy = y2 - y1;
  273.     sdx = sign(dx);
  274.     sdy = sign(dy);
  275.     dxabs = abs(dx);
  276.     dyabs = abs(dy);
  277.     x = 0;
  278.     y = 0;
  279.     px = x1;
  280.     py = y1;
  281.  
  282.  
  283.             mask = mask ? mask : 0x80000000;
  284.             if (PATTERN & mask)
  285.             {
  286.                 for (j= -LINEWIDTH/2; j<=LINEWIDTH/2; j++)
  287.                     screenbit[px][py+j] = '#';
  288.  
  289.             }
  290.             mask >>= 1;
  291.  
  292.  
  293.     if (dxabs >= dyabs)
  294.     {
  295.         for (i=0; i<dxabs; i++)
  296.         {
  297.             mask = mask ? mask : 0x80000000;
  298.             y += dyabs;
  299.             if (y>=dxabs)
  300.             {
  301.                 y -= dxabs;
  302.                 py += sdy;
  303.             }
  304.             px += sdx;
  305.             if (PATTERN & mask)
  306.             {
  307.                 for (j= -LINEWIDTH/2; j<=LINEWIDTH/2; j++)
  308.                     screenbit[px][py+j] = '#';
  309.  
  310.             }
  311.             mask >>= 1;
  312.         }
  313.     }
  314.     else
  315.     {
  316.         for (i=0; i<dyabs; i++)
  317.         {
  318.             mask = mask ? mask : 0x80000000;
  319.             x += dxabs;
  320.             if (x>=dyabs)
  321.             {
  322.                 x -= dyabs;
  323.                 px += sdx;
  324.             }
  325.             py += sdy;
  326.             if (PATTERN & mask)
  327.             {
  328.                 for (j= -LINEWIDTH/2; j<=LINEWIDTH/2; j++)
  329.                     screenbit[px+j][py] = '#';
  330.             }
  331.             mask >>= 1;
  332.         }
  333.     }
  334. }
  335. /*---------------------------------------------------------------------------*/
  336. d_clear()
  337. {
  338.     int x,y;
  339.     for (y=0;y<=MAXY;y++) {
  340.       for (x=0;x<=MAXX;x++) {
  341.         screenbit[x][y] = 0;
  342.       }
  343.     }
  344. }
  345. /*---------------------------------------------------------------------------*/
  346. d_flush()
  347. {
  348. }
  349. /*---------------------------------------------------------------------------*/
  350. d_arcto(dbl x1,dbl y1,dbl x2,dbl y2,dbl rrr)
  351. {
  352.     df_arcto(x1,y1,x2,y2,rrr);
  353. }
  354. /*---------------------------------------------------------------------------*/
  355. d_arc(dbl r,dbl t1,dbl t2,dbl cx,dbl cy)
  356. {
  357.     df_arc(r,t1,t2,cx,cy);
  358. }
  359. /*---------------------------------------------------------------------------*/
  360. d_narc(dbl r,dbl t1,dbl t2,dbl cx,dbl cy)
  361. {
  362.     /* swap t1 t2*/
  363.     df_arc(r,t2,t1,cx,cy);
  364. }
  365. /*---------------------------------------------------------------------------*/
  366. d_box_fill(dbl x1, dbl y1, dbl x2, dbl y2)
  367. {
  368.     df_box_fill(x1,y1,x2,y2);
  369. }
  370. d_box_stroke(dbl x1, dbl y1, dbl x2, dbl y2)
  371. {
  372.     df_box_stroke(x1,y1,x2,y2);
  373. }
  374. /*---------------------------------------------------------------------------*/
  375. d_circle_stroke(double zr)
  376. {
  377.     df_circle_stroke(zr);
  378. }
  379. d_circle_fill(double zr)
  380. {
  381.     df_circle_fill(zr);
  382. }
  383. /*---------------------------------------------------------------------------*/
  384. d_bezier(dbl x1,dbl y1,dbl x2,dbl y2,dbl x3,dbl y3)
  385. {
  386.     double ax,bx,cx,ay,by,cy,dist;
  387.     double xxx,yyy,i,t,nstep,x0,y0;
  388.     g_get_xy(&x0,&y0);
  389.     dist = fabs(x3-x0) + fabs(y3-y0);
  390.     nstep = 10;
  391.     if (dist>3) nstep = 20;
  392.     if (dist<.5) nstep = 5;
  393.     if (dist<.3) nstep = 3;
  394.     if (dist<.1) {
  395.         g_line(x3,y3);
  396.         return;
  397.     }
  398.     cx = (x1-x0)*3;
  399.     bx = (x2-x1)*3-cx;
  400.     ax = x3-x0-cx-bx;
  401.     cy = (y1-y0)*3;
  402.     by = (y2-y1)*3-cy;
  403.     ay = y3-y0-cy-by;
  404.     for (i=0;i<=nstep;i++) {
  405.         t = i/nstep;
  406.         xxx = ax*pow(t,3.0) + bx*t*t + cx*t + x0;
  407.         yyy = ay*pow(t,3.0) + by*t*t + cy*t + y0;
  408.         g_line(xxx,yyy);
  409.     }
  410. }
  411. /*---------------------------------------------------------------------------*/
  412. d_set_color(int32 f)
  413. {
  414. }
  415. d_set_fill(int32 f)
  416. {
  417. }
  418. /*---------------------------------------------------------------------------*/
  419. d_beginclip()
  420. {
  421. }
  422. d_endclip()
  423. {
  424. }
  425. struct char_data {float wx,wy,x1,y1,x2,y2; };
  426. int font_get_chardata(struct char_data **cd, int ff, int cc);
  427. /*---------------------------------------------------------------------------*/
  428. d_char(int font, int cc)
  429. {
  430.     static struct char_data cd;
  431.     static int ix,iy,ix1,ix2,iy1,iy2,fz,fzx;
  432.     static int ux,uy;
  433.     static int safnt;
  434.     char ss[2];
  435.  
  436.     ss[0] = cc;
  437.     ss[1] = 0;
  438.     if (safnt==0) safnt = pass_font("PLSR");
  439.     if (font>=2) {
  440.         my_char(font,cc);
  441.         return;
  442.     }
  443.     my_char(safnt,cc);
  444. }
  445.  
  446.  
  447.  
  448.